const query = (function() {
    const query = {};
    /** 不需要分两步取值 */
    const search = /.*\?([^\?]+)/.exec(location.href)[1];
    /** 使用三元直接赋值 */
    const searchArr = search.indexOf("&") ? search.split("&") : search.split();

    searchArr.forEach((item) => {
        const queryArr = item.split("=");
        query[queryArr[0]] = queryArr[1];
    });

    return query;
})();
console.log(query);
fetch("http://chst.vip:1234/api/getcategorybyid?categoryid=" + query.categoryid)
    .then(body => body.json())
    .then(res => {
        res.result.forEach(item => {
            // console.log(item);
            classify.innerHTML = `
                <a href="bijia.html?title=${item.category}&categoryid=${item.categoryId}">${item.category}></a>
                   `
            price.innerHTML = `
            ￥${query.price}.00
            `
        })
        fetch("http://chst.vip:1234/api/getproduct?productid=" + query.productid)
            .then(body => body.json())
            .then(res => {
                res.result.forEach(item => {
                    // console.log(item);
                    commodity.innerHTML = `
                    <a href class="menu fl">${item.productName}</a>
                    `
                    info.innerHTML = `
                    <div class="pic">${item.productImg}</div>
                    <div class="title">${item.productName}</div>
                    <div class="count">
                        <div class="row">
                            <div class="col-xs-6">
                                <span>当前最低</span>
                                <span>￥6000</span>
                            </div>
                            <div class="col-xs-6">
                                <span>优选评论</span>
                                <span>8266条</span>
                            </div>
                        </div>
                    </div>
                    `
                })
            })
    })
fetch("http://chst.vip:1234/api/getproductcom?productid=" + query.productid)
    .then(body => body.json())
    .then(res => {
        res.result.forEach(item => {
            console.log(item);
            appraise.innerHTML += `
            <div class="content clearfix">
            <div class="up clearfix">
                <span class="fl">${item.comName}</span>
                <span class="fr">${item.comTime}</span>
            </div>
            <div class="content_in">${item.comContent}</div>
            <div class="from fr">
                <span>${item.comFrom}</span>
            </div>
            </div>
            `
        })
    })